<?php

namespace app\common\validate;

use think\Validate;

class User extends Validate
{
    protected $regex = ['mobile' => '^1\d{10}$'];

    /**
     * 验证规则
     */
    protected $rule = [
        'username'          => 'require|unique:User,username',
        'mobile'            => 'require|mobile|unique:User,mobile',

    ];
    /**
     * 提示消息
     */
    protected $message = [
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['username', 'mobile'],
        'edit' => ['username' => 'require|unique:User,username^id', 'mobile' => 'require|mobile|unique:User,mobile^id']
    ];

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'username' => __('用户名'),
            'mobile' => __('手机号'),
        ];
        parent::__construct($rules, $message, $field);
    }
    
}
